/*
 * Powered By fanrenqij.com
 * Since 2017 - 2017
 */

package com.fanrenqiji.modules.business.messagetemplate.dao;

import com.fanrenqiji.common.persistence.BaseDao;
import com.fanrenqiji.common.persistence.BaseDaoImpl;
import com.fanrenqiji.entity.MessageTemplateEntity;
import org.hibernate.sql.Select;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
/**
 * 持久化接口
 */
public interface MessageTemplateDao extends MessageTemplateDaoCustom, CrudRepository<MessageTemplateEntity, Long> {

    @Query("from MessageTemplateEntity where delFlag='" + MessageTemplateEntity.DEL_FLAG_NORMAL + "' order by id desc")
    public List<MessageTemplateEntity> findAllList();


    @Query("from MessageTemplateEntity where delFlag='" + MessageTemplateEntity.DEL_FLAG_NORMAL + "' and status =?1 order by id")
    public List<MessageTemplateEntity> findMessageTemplateEntityByStatus(int status);

    @Modifying
    @Query("update MessageTemplateEntity set delFlag='" + MessageTemplateEntity.DEL_FLAG_DELETE + "' where id = ?1 ")
    void deleteById(Long id);

    @Query("select templateContent from MessageTemplateEntity where id=?1 ")
   String getContentById(Long id);

}


interface MessageTemplateDaoCustom extends BaseDao<MessageTemplateEntity> {
}

@Repository
class MessageTemplateDaoImpl extends BaseDaoImpl<MessageTemplateEntity> implements MessageTemplateDaoCustom {

}
